package com.szxydb.dmp.config;

import com.szxydb.dmp.interceptor.AdminAuthInterceptor;
import com.szxydb.dmp.interceptor.AdminTokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Bean
    public HandlerInterceptor adminAuthInterceptor(){
        return new AdminAuthInterceptor();
    }

    @Bean
    public HandlerInterceptor adminTokenInterceptor(){
        return new AdminTokenInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(adminTokenInterceptor()).
                addPathPatterns("/api/admin/**").
                excludePathPatterns("/api/admin/validate/**")
                .excludePathPatterns("/api/admin/login")
                .excludePathPatterns("/api/admin/logout")
                .excludePathPatterns("/api/admin/getLoginPic");

        registry.addInterceptor(adminAuthInterceptor())
                .addPathPatterns("/api/admin/**")
                .excludePathPatterns("/api/admin/validate/**")
                .excludePathPatterns("/api/admin/login")
                .excludePathPatterns("/api/admin/logout")
                .excludePathPatterns("/api/admin/getLoginPic");
    }
}
